package com.kantboot.business.bp.repository;

import com.kantboot.business.bp.domain.entity.BusBpGradeAndSubject;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BusBpGradeAndSubjectRepository extends JpaRepository<BusBpGradeAndSubject, Long> {

    /**
     * 根据年级ID查询年级和学科(根据学科优先级倒序排序)
     * @param gradeId 年级ID
     * @return 年级和学科
     */
    @Query("""
            FROM BusBpGradeAndSubject g
            WHERE g.gradeId = :gradeId
            ORDER BY g.subject.priority DESC
            """)
    List<BusBpGradeAndSubject> findByGradeId(Long gradeId);

    /**
     * 根据学科ID查询年级和学科(根据学科优先级倒序排序)
     * @param subjectId 学科ID
     * @return 年级和学科
     */
    @Query("""
            FROM BusBpGradeAndSubject g
            WHERE g.subjectId = :subjectId
            ORDER BY g.subject.priority DESC
            """)
    List<BusBpGradeAndSubject> findBySubjectId(Long subjectId);

}
